package com.oh.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.oh.activity.R;
import com.oh.activity.SetUpActivity;
import com.oh.database.PreferencesManager;

/**
 * 
 * 
 * @author Alex.Lu
 *
 */
public class DialogManager implements OnClickListener {

	private static DialogManager instance;
	private Dialog mDialog;
	
	public static DialogManager getInstance(){
		if(instance == null){
			instance = new DialogManager();
		}
		return instance;
	}
	
	
	public void createLoginAdmin(final Context context,OnClickListener listener){
		mDialog = new Dialog(context,R.style.dialog_a);
		LayoutInflater mInflater = LayoutInflater.from(context);
		View view = mInflater.inflate(R.layout.dialog_login_admin, null);
		final EditText passwordET = (EditText)view.findViewById(R.id.password);
		Button ok = (Button)view.findViewById(R.id.ok);
		ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mDialog.dismiss();
				String password = passwordET.getText().toString();
				if(PreferencesManager.getInstance().getPassword().equals(password)){
					Intent intent = new Intent();
					intent.setClass(context, SetUpActivity.class);
					context.startActivity(intent);
				}else{
					//提示错误
					Toast.makeText(context, R.string.msg_password_wrong, Toast.LENGTH_LONG).show();
				}
				
				
			}
		});
		
		Button cancel = (Button)view.findViewById(R.id.cancel);
		cancel.setOnClickListener(this);
		
		mDialog.setContentView(view,new LayoutParams(400,300));
		mDialog.show();
	}

	
	public void dismiss(){
		mDialog.dismiss();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		mDialog.dismiss();
	}
	
	
}
